<?php
namespace app\customer\controller;
use think\Db;
class User extends Base{
    public function user_list(){
        $key=input('get.key');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $list=Db::name('users')->where('cus_id',session('customer')['id'])->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('nickname','like',"%{$key}%")->order('id desc')->paginate(10);
        $lists=Db::name('users')->where('cus_id',session('customer')['id'])->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('nickname','like',"%{$key}%")->select();
        $data=$list->all();
        $this->assign('key',input('get.key'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function enlist_list(){
        $key=input('get.key');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $list=Db::name('enlist')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('users c', 'a.openid = c.openid','LEFT')->field('a.*,b.title,c.nickname,c.avatar')->where('a.cus_id',session('customer')['id'])->where('a.time','>',"{$fromtime}")->where('a.time','<',"{$totime}")->where('a.name|a.phone|a.inviter|b.title|c.nickname','like',"%{$key}%")->order('id desc')->paginate(10);
        $lists=Db::name('enlist')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('users c', 'a.openid = c.openid','LEFT')->field('a.*,b.title,c.nickname,c.avatar')->where('a.cus_id',session('customer')['id'])->where('a.time','>',"{$fromtime}")->where('a.time','<',"{$totime}")->where('a.name|a.phone|a.inviter|b.title|c.nickname','like',"%{$key}%")->select();
        $data=$list->all();
        $this->assign('key',input('get.key'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function collect_list(){
        $key=input('get.key');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $list=Db::name('collect')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('users c', 'a.openid = c.openid','LEFT')->field('a.*,b.title,c.nickname,c.avatar')->where('a.cus_id',session('customer')['id'])->where('a.time','>',"{$fromtime}")->where('a.time','<',"{$totime}")->where('b.title|c.nickname','like',"%{$key}%")->order('id desc')->paginate(10);
        $lists=Db::name('collect')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('users c', 'a.openid = c.openid','LEFT')->field('a.*,b.title,c.nickname,c.avatar')->where('a.cus_id',session('customer')['id'])->where('a.time','>',"{$fromtime}")->where('a.time','<',"{$totime}")->where('b.title|c.nickname','like',"%{$key}%")->select();
        $data=$list->all();
        $this->assign('key',input('get.key'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
}
